<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<jsp:include page="/WEB-INF/views/layouts/header.jsp" />
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
// 网站地址
String netPath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
%>
<style>
.yhgltable ul li span.current {
	font-weight: bold
}

.chooseColumn {
	width: 196px;
	height: 30px;
	line-height: 30px;
	color: #666;
	border: 1px solid #BBB;
}

.chooseColumn option {
	height: 30px;
}

.next,.prev {
	filter: Alpha(opacity =50);
	-moz-opacity: .1;
	opacity: 0.5;
}
</style>
<script type="text/javascript">
	
	// 局部刷新
	function refreshAds(){
		$(".userContent").load("<%=basePath%>ad/showAds");
	};
	
 	function toInsert(){

		var url = "<%=basePath%>ad/add";
		var HTML = '<div class="Popup">';
		HTML += '<div class="Popupheader"><a node-type="close" href="#"><img src="<%=basePath%>images/Popupclose01.png" width="28" height="28"></a></div>';
		HTML += '<div class="Popup_A"><div class="Popup_A_1">';
				HTML += '<div class="Popup_title"><h2>增加公告</h2></div>';
				HTML += '<iframe width="100%" height="400" src="'+ url +'" scrolling="no" frameborder="0"></iframe>';
				HTML += '</div></div>'
				HTML += '<div class="Popupfoot"><img src="<%=basePath%>images/Popupbg01_footer.png" width="550" height="15"></div></div>';
		$.dialog({skin:false,content:HTML});
	};

	/**
	 *把指定的一组checkbox所选的值构造为逗号分隔的字符串
	 */
	function getAllValue(group_box) {
		var boxes = document.getElementsByName(group_box);
		var values = "";
		for (var i = 0; i < boxes.length; i++) {
			if (boxes[i].checked) {
				values += boxes[i].value + ",";
			}
		}
		if (values.length > 0) {
			values = values.substring(0, values.length - 1);
		}
		return values;
	};

	function toDelete(){
		var operatorIds = getAllValue("group_box");
		//alert(operatorIds);
		if(!operatorIds){
			alert("请选择需要删除的公告！");
			return;
		}
		if(confirm("确认删除这些公告？")){
			$.ajax({
			  url: "<%=basePath%>ad/toDelete",
			  type:"POST",
			  contentType:"application/x-www-form-urlencoded; charset=utf-8",
			  data: "strAdIds="+operatorIds,
			  dataType: 'text',
			  success: function(data) {
				 var jsonobj=eval('('+data+')');
				 if(jsonobj.state==='1'){
					refreshAds();
					alert(jsonobj.result);
				 } else if(jsonobj.state==='0'){
					 alert(jsonobj.result);
				 }
			  },
			  error: function(XMLHttpRequest, textStatus, errorThrown) {
					 alert("删除失败！");
			  }
			});
		}
	};
	
	function toUpdate(linkId){

		var url = "<%=basePath%>ad/update?linkId="+linkId;
		var HTML = '<div class="Popup">';
		HTML += '<div class="Popupheader"><a node-type="close" href="#"><img src="<%=basePath%>images/Popupclose01.png" width="28" height="28"></a></div>';
		HTML += '<div class="Popup_A"><div class="Popup_A_1">';
				HTML += '<div class="Popup_title"><h2>修改栏目</h2></div>';
				HTML += '<iframe width="100%" height="400" src="'+ url +'" scrolling="no" frameborder="0"></iframe>';
				HTML += '</div></div>'
				HTML += '<div class="Popupfoot"><img src="<%=basePath%>images/Popupbg01_footer.png" width="550" height="15"></div></div>';
		$.dialog({skin:false,content:HTML});
	};
	

	//0: 上升  1：下降
	function changePosStat(cid,intFlag){

		$.ajax({
			  url: "<%=basePath%>ad/changePos",
			  type:"POST",
			  contentType:"application/x-www-form-urlencoded; charset=utf-8",
			  data: {"adId":cid,"intFlag":intFlag},
			  dataType: 'text',
			  success: function(data) {
				 var jsonobj=eval('('+data+')');
				 if(jsonobj.state==='1'){
					 refreshAds();
					alert(jsonobj.result);
				 } else if(jsonobj.state==='0'){
					 alert(jsonobj.result);
				 }
			  },
			  error: function(XMLHttpRequest, textStatus, errorThrown) {
					 alert("修改失败！");
			  }
		});
		
	};
</script>
<!--中间部分开始-->
<div class="main">
	<!-- /左侧 -->
	<!-- 核心内容区域 -->
	<div id="iaas_layout_content" class="rightblock" style="margin-left:0;">
		<p class="shadow"></p>
		<div class="content">
			<!--默认状态下引用样式ml60，展开后引用样式ml140-->
			<div class="mainblock">
				<div class="tabA">
					<h1>
						<a href="<%=basePath%>ad/operate" style="color:#585858">公告管理</a>
					</h1>
				</div>
				<div class="lineone mt10">
					<div class="btn">
						<a href="javascript:void(0)" onclick="toInsert()"><img
							src="<%=basePath%>images/xz.gif" />新增</a> <a href="javascript:void(0)"
							onclick="toDelete()"><img
							src="<%=basePath%>images/del.gif" />删除</a>
					</div>
				</div>

				<table border="0" cellpadding="0" cellspacing="0"
					class="yhgltable mt10" style="width:100%">
					<tr>
						<td rowspan="2" class="userContent" valign="top"><script>
			            		$(".userContent").load("<%=basePath%>ad/showAds");
			            	</script>
			            </td>
					</tr>
				</table>
			</div>
		</div>
	</div>
</div>
<!--中间部分结束-->
<!--底部开始-->
<jsp:include page="/WEB-INF/views/layouts/footer.jsp" />
<!--底部结束-->
</body>
</html>
